package cn.tedu.boot02.utils;

import com.alibaba.druid.pool.DruidDataSource;

import java.sql.Connection;
import java.sql.SQLException;

public class DBUtil {
    private static DruidDataSource dds;


    static {
        initDataSource();
    }
    private static void initDataSource(){
        dds=new DruidDataSource();
        dds.setUsername("root");
        dds.setPassword("root");
        dds.setUrl("jdbc:mysql://localhost:3306/birddb?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true");
        dds.setInitialSize(5);
        dds.setMaxActive(50);
    }
    public static Connection getConnection() throws SQLException {
        /*
        Connection connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/"+dbName+"?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                "root","root");
        return connection;

         */
        return dds.getConnection();
    }
}
